package com.freight.user.controller;

import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.utils.SecurityUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.core.entity.User;
import com.freight.user.dto.*;
import com.freight.user.entity.DriverUser;
import com.freight.user.service.DriverUserService;
import com.freight.user.vo.DriverAllPicId;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "司机用户信息表管理接口")
@RequestMapping("/freight/driverUser")
@Transactional
public class UserDriverController {

    @Autowired
    private DriverUserService driverUserService;


    @RequestMapping(value = "/saveDriverInfo", method = RequestMethod.POST)
    @ApiOperation(value = "保存司机信息-----")
    public Result<String> saveDriverInfo(DriverInfoDto driverInfoDto) {
        driverUserService.saveDriverInfo(driverInfoDto);
        return ResultUtil.data("保存成功");
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<DriverUser>> getByCondition(DriverUser driverUser, SearchVo searchVo, PageVo pageVo) {
        Page<DriverUser> page = driverUserService.findByCondition(driverUser, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<DriverUser>>().setData(page);
    }

    @RequestMapping(value = "/getDriverPicId", method = RequestMethod.GET)
    @ApiOperation(value = "获取司机所有Id")
    public Result<DriverAllPicId> getCompanyPicId(Long userId) {
        DriverAllPicId res = driverUserService.getDriverPicId(userId);
        return new ResultUtil<DriverAllPicId>().setData(res);
    }

}
